package dao

import (
	"fmt"
	"hft/Http/Models/request"

	"gorm.io/gorm"
)

type GetArticle struct{}

func (g *GetArticle) GetArticleList(regionLink string, paginate *request.ArtSearchReq, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	var nameLike = fmt.Sprintf("%v%%", paginate.Name)
	var authorLike = fmt.Sprintf("%v%%", paginate.Author)
	return func(db *gorm.DB) *gorm.DB {
		return db.Omit("pure_text").Where("region_link = ?", regionLink).Where("name LIKE ? AND author LIKE ?", nameLike, authorLike).Where(paginate.ArtSearchInfo).Omit("account_id,account_link").Scopes(BaseDao.CreateTime(db, paginate.CreateTime)).Order("create_time desc").Scopes(Paginate(Page(paginate.Page), db))
	}
}

var GetArticleDao = new(GetArticle)
